{include file="common/head"/}
<style>
	.sele {
		height: 37px;
		width: 200px;
		border: 1px solid #E6E6E6;
	}

	.layui-table .layui-table-cell{
		height: auto;
	}
</style>
<div class="admin-main layui-anim layui-anim-upbit">
	<input type="hidden" name="pageId" value="{$pageId}" id='pageId'>
	<fieldset class="layui-elem-field layui-field-title">
		<legend>全部用户</legend>
	</fieldset>

	<!-- 不需要 -->
	<div class="demoTable">
		<form class="layui-form layui-form-pane">
			<input type="hidden" id="hidStoreId">

			<!-- 姓名 S -->
			<div class="layui-inline">
				<input type="text" name="title" id="key" ng-model="field.title" placeholder="请输入姓名" class="layui-input" autocomplete="off">
			</div>
			<!-- 姓名 E -->

			<!-- 手机号 S -->
			<div class="layui-inline">
				<input type="text" name="title" id="mobile" ng-model="field.mobile" placeholder="请输入手机号" class="layui-input" autocomplete="off">
			</div>
			<!-- 手机号 E -->

			<!-- 类型 S -->
			<div class="layui-inline">
				<select name="identity" id="identity">
					<option value="">请选择用户类型</option>
					<!--Each S-->
					{foreach $identityList as $key=>$val }
					<option value="{$val.id}" >{$val.title}</option>
					{/foreach}
					<!--Each E-->
				</select>
			</div>
			<!-- 类型 E -->

			<!-- 道馆 S -->
			<div class="layui-inline">
				<select name="store_id" id="store_id" xm-select="store_id" xm-select-search="{:url('admin/QuanGuanMemberController/storeTojson')}" xm-select-radio="">
					<option value="">请选择道馆</option>
				</select>
			</div>
			<!-- 道馆 E -->

			<button class="layui-btn" id="search" type="button" data-type="reload">搜索</button>
			<a href="{:url('index')}" class="layui-btn">显示全部</a>
		</form>
	</div>
	<!-- 不需要 -->


	<table class="layui-table" id="list" lay-filter="list"></table>

</div>

<!-- 需要（编辑的方法名称 主键id 的名称 start-->
<script type="text/html" id="action">
	<a href="{:url('update')}?id={{d.id}}" class="layui-btn layui-btn-xs">编辑</a>    <!-- 主键 -->
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>
<!-- 需要（编辑的方法名称 主键id 的名称 end-->



<!-- 需要 添加的方法名称 按钮的的title -->
<script type="text/html" id="topBtn">
	<!-- 新页面打开 -->
	<a href="{:url('create')}" class="layui-btn  layui-btn-sm" >添加</a>
	<!-- 弹窗打开 -->
<!--	<a href="javascript:;" class="layui-btn  layui-btn-sm" id="popBtn" >添加</a>-->
</script>
<!-- 需要 添加的方法名称 按钮的的title -->


<script type="text/html" id="image"> <img src="{{d.image}}" style="height: 100px;width: 100px;" /></script>

<script type="text/html"
	id="status"><input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="status" {{ d.status == 2 ? "checked" : "" }}></script>

<script type="text/html" id="name"> <a  style="color: #00acc1" href="{:url('update')}?id={{d.id}}">{{d.name}}</a> </script>


{include file="common/foot"/}

<link href="/static/common/css/formSelects-v4.css" rel="stylesheet" />
<script>
	layui.config({
		base: '/static/common/js/' //此处路径请自行处理, 可以使用绝对路径
	}).extend({
		formSelects: 'formSelects-v4'
	});

	layui.use(['table', 'form', 'formSelects'], function () {

		var table = layui.table,
			form = layui.form,
			$ = layui.jquery;
			layer = layui.layer

		var pageId = $('#pageId').val();

		var formSelects = layui.formSelects;
		formSelects.btns('store_id', []);
		formSelects.on('store_id',function (id, vals, val, isAdd, isDisabled){
			$("#hidStoreId").val(val.value);
		});


		var exportData = '';
		var tableIn = table.render({
			id: 'user',
			elem: '#list',
			url: '{:url("index")}',
			method: 'post',
			toolbar: '#topBtn',
			totalRow: true,
			page: { curr: pageId },
			cols: [
				[

					{
						field: 'id',
						title: 'ID',
						width: 80
					},

					{
						field: 'image',
						title: '头像',
						width: 150,
						toolbar: '#image',
					},

					{
						field: 'name',
						title: '姓名',
						width: 200,
						toolbar : '#name'
					},

					{
						field: 'mobile',
						title: '手机号（账号）',
						width: 160
					},

					{
						field: 'identity',
						title: '类型',
						width: 120
					},

					{
						field: 'store_id',
						title: '关联单位',
						width: 200
					},

					{
						field: 'gender',
						title: '性别',
						width: 60
					},

					{
						field: 'age',
						title: '年龄',
						width: 60
					},

					{
						field: 'weight',
						title: '体重',
						width: 60
					},

					{
						field: 'province_id',
						title: '省',
						width: 120
					},

					{
						field: 'city_id',
						title: '市',
						width: 120
					},

					{
						field: 'area_id',
						title: '区',
						width: 120
						// ,align: 'center'
					},

					{
						field: 'create_time',
						title: '注册时间',
						width: 160
					},

					// {
					// 	field: 'status',
					// 	title: '是否禁用',
					// 	toolbar: '#status',
					// 	width: 200
					// },

					{
						width: 160,
						align: 'center',
						toolbar: '#action'
					}

				]
			],
			done: function (res, curr, count) {
				exportData = res.data; //获取表格中的数据集合。
				// setTimeout(function () {
				// 	if (sessionStorage.getItem('now_page')) {
				// 		sessionStorage.removeItem('now_page');
				// 	}else {
				// 		sessionStorage.setItem('now_page', curr);
				// 	}
				// }, 1000)
			},
		});

		//搜索
		$('#search').on('click', function () {
			var key = $('#key').val();
			var identity = $('#identity').val();
			var mobile = $('#mobile').val();
			var storeId = $('#hidStoreId').val();

			tableIn.reload({
				page: {
					page: 1
				},
				where: {
					key: key,
					identity: identity,
					mobile: mobile,
					store_id: storeId,
				}
			});
		});

		table.on('tool(list)', function (obj) {
			var data = obj.data;
			if (obj.event === 'del') {
				layer.confirm('您确定要删除这条信息吗？', function (index) {
					var loading = layer.load(1, {
						shade: [0.1, '#fff']
					});
					$.post("{:url('remove')}", {
						id: data.id
					}, function (res) { //主键
						layer.close(loading);
						if (res.code === 1) {
							layer.msg(res.msg, {
								time: 1000,
								icon: 1
							});
							tableIn.reload();
						} else {
							layer.msg('操作失败！', {
								time: 1000,
								icon: 2
							});
						}
					});
					layer.close(index);
				});
			}
		});

		form.on('switch(status)', function (obj) {
			loading = layer.load(1, {
				shade: [0.1, '#fff']
			});
			var id = this.value;
			var status = obj.elem.checked === false ? 1 : 2;
			$.post('{:url("setStatus")}', {
				'id': id,
				status: status
			}, function (res) {
				layer.close(loading);
				if (res.code == 1) {
					location.reload();
				} else {
					layer.msg(res.msg, {
						time: 1000,
						icon: 2
					});
					return false;
				}
			})
		});

		$("#popBtn").on('click',function (e){
			console.log(layer);
			var addLay = layer.open({
				type : 1
				, skin: 'layui-layer-molv'//墨绿主题颜色
				, area: ['800px']//模态框大小，尽量比form表单大
				, title: ['新增', 'font-size:18px;text-align:center']
				, btn: ['保存', '取消']
				, closeBtn: 0
				, shadeClose: true// 点击遮罩区域，关闭弹层
				, shade: 0.2 //遮罩透明度
				, content: '<iframe src="create.html" style="width: 900px; height: 600px;"></iframe>'//将form表单追加到弹窗中
				// , content: $('#AddForm')//将form表单追加到弹窗中
			});
		});

	});
</script>
</body>

</html>